const express = require('express');
const router = express.Router();
const ShopInterface = require('../service/shop');
const shopInterface = new ShopInterface();
router.get('/List/:page?',async function(req,res,next){
	const page = req.params['page'];
	var data = await shopInterface.findAll(page);
	res.json({status:'success',data:data})
})
.get('/add',async function(req,res,next){
	const query = req.query;
	try{
	 	var effect = await shopInterface.add(query);
	    res.json({'effect':effect})
	}catch(err){
		 res.json({status:'error',effect:0})
	}
})
.get('/update/:id?',async function(req,res,next){
    const id = req.params['id'];
	const query = req.query;
	try{
	 	var effect = await shopInterface.update(id,query);
	    res.json({'effect':effect})
	}catch(err){
		 res.json({status:'error',effect:0})
	}
})
.get('/del/:id?',async function(req,res,next){
	 const id = req.params['id'];
	 try{
	 	 var count = await shopInterface.deleteOne(id);
		 res.json({status:'success',effect:count})
	 }catch(err){
		 res.json({status:'error',effect:0})
	 }
})
.get('/:id?',async function(req,res,next){
	 const id = req.params['id'];
	 var data = await shopInterface.findOne(id);
	 res.json({status:'success',data:data})
})


module.exports = router;